package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.vo.CoursePublicVo;
import com.atguigu.eduservice.entity.vo.courseInfoVo;
import com.atguigu.eduservice.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-10-30
 */
@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    @Autowired
    private EduCourseService courseService;


    @GetMapping
    public R getCourseList(){
        List<EduCourse> list = courseService.list(null);
    return R.ok().data("list",list);
    }


    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody courseInfoVo courseInfoVo){
      String id=  courseService.saveCourseInfo(courseInfoVo);
        return R.ok().data("courseId",id);
    }

    @GetMapping("getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId){
     courseInfoVo courseInfoVo =courseService.getCourseInfo(courseId);
     return R.ok().data("courseInfo",courseInfoVo);
    }

   @PostMapping("updateCourseInfo")
    public R updateCourseInfo(@RequestBody courseInfoVo courseInfoVo){
        courseService.updateCourseInfo(courseInfoVo);
      return R.ok();
 }

  @GetMapping("getPublicCourseInfo/{id}")
    public R getPublicCourseInfo(@PathVariable String id){
     CoursePublicVo coursePublicVo= courseService.publicCourseInfo(id);
     return R.ok().data("publicCourse",coursePublicVo);
    }

    @PostMapping("publicCourse/{id}")
    public R publicCourse(@PathVariable String id){
        EduCourse eduCourse=new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");
        courseService.updateById(eduCourse);
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deleteCourse(@PathVariable String id){
        courseService.removeCourse(id);
        return R.ok();
    }

}

